#load "extLib.cma";;

let tests = ref [];;

let addtest desc test expected =
  tests := (desc, test, expected) :: !tests;;

let cleartests() =
  tests := [];;

let rec runtestshelper = function
    [] -> [];
  | (desc, test, expected)::rest ->
    let _ = print_endline ("Running " ^ desc) in
    let result = test() in let _ =
      if result = expected
        then []
        else let _ =
          print_endline (desc ^ " failed.") in let _ =
          print_string "\tExpected: " in let _ =
          Std.print expected in let _ =
          print_string "\tActual: " in let _ =
          Std.print result in []
      in
    runtestshelper rest;;
  
let runtests() =
  let _ = runtestshelper (List.rev !tests) in
  print_endline "Done.";;
